package com.wl2o2o.lanqiao.xzfourteen;

import java.util.ArrayList;
import java.util.Collections;


/** 
* @author : WLei224
* @date ：2023年3月27日 上午12:42:24 
* 
*/
public class Java对象多关键字排序 {

	public static void main(String[] args) {
		ArrayList<Student> list = new ArrayList<>();
		list.add(new Student("张三",100,59));
		list.add(new Student("李四",100,100));
		list.add(new Student("王五",98,96));
		list.add(new Student("赵六",96,98));
		list.add(new Student("陈七",59,100));
		//根据其元素的natural ordering对指定的列表进行排序。
		Collections.sort(list);
		for(int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i));
		}
	}
	

}
class Student implements Comparable<Student>{
	String sname;
	int java;
	int mysql;
	int score;
	
	public Student() {};
	public Student(String sname, int java, int score) {
		this.sname = sname;
		this.java = java;
		this.mysql = mysql;
		this.score = java + mysql;
	}
	//重写tostring方法
	public String toString() {
		return "sname" + this.sname + "\tjava" + this.java + "\tmysql" + this.mysql + "\tscore" + this.score;
	}
	//写比较规则
	@Override
	public int compareTo(Student stu) {
		if(this.score > stu.score)return -1;
		else if(this.score<stu.score)return 1;
		else {
			if(this.java>stu.java)return -1;
			else if(this.java < stu.java)return 1;
			else return 0;
		}
	}
}